﻿using System.Windows;
using System.Windows.Input;
using Rio.Framework.Localisation;
using Rio.Framework.Pages.ModalControls;

namespace Rio.Framework.Pages.Manager
{
    public static class SplashScreenManager
    {
        public static SplashScreen SplashScreen = new SplashScreen();
        
        /// <summary>
        /// Initialize the Wait cursor
        /// </summary>
        public static void Wait(FrameworkElement p_oFWElement)
        {
            SplashScreen.Message = Resx.GetLabel(ResxCommon.SPLASHSCREEN_MESSAGE);
            SplashScreen.MessageDetail = string.Empty;
            
            SplashScreenLaunch();
            
            p_oFWElement.Cursor = Cursors.Wait;
        }

        public static void WaitDetail(FrameworkElement p_oFWElement, string p_sDetail)
        {

            SplashScreenClose();
            SplashScreen.Message = Resx.GetLabel(ResxCommon.SPLASHSCREEN_MESSAGE);
            SplashScreen.MessageDetail = p_sDetail;

            SplashScreenLaunch();

            p_oFWElement.Cursor = Cursors.Wait;
        }
        /// <summary>
        /// Restore the normal cursor
        /// </summary>
        public static void Stop(FrameworkElement p_oFWElement)
        {
            SplashScreenClose();
            
            p_oFWElement.Cursor = Cursors.Arrow;
        }
        
        /// <summary>
        /// Lauch the splash screen
        /// </summary>
        private static void SplashScreenLaunch()
        {
            SplashScreen.Show();
            
            ModalDialogController.Launch(SplashScreen);
        }
        /// <summary>
        /// Lauch the splash screen
        /// </summary>
        private static void SplashScreenClose()
        {
            ModalDialogController.Close();
            
            SplashScreen.Close();
        }

    }
}
